package com.yzt.dynamicmodule.presenter;

import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.user.FollowUserStatusRequest;
import com.yzt.dynamicmodule.contacts.DynamicListContacts;
import com.yzt.plugin_network.response.HttpResponse;

import java.util.ArrayList;
import java.util.List;

public class ActivityListPresenter extends DynamicListContacts.Presenter {

    @Override
    public void delDynamic(String dynamicId) {
        BizLayer.getInstance().getDynamicModule().dynamicDel(dynamicId, new AresSubscriber<HttpResponse>() {
            @Override
            protected void onSuccess(HttpResponse httpResponse) {
                mView.delDynamic();
            }
        });
    }

    @Override
    public void dynamicLike(String dynamicId, boolean like, int position) {
        if (like) {
            BizLayer.getInstance().getDynamicModule().dynamicLike(dynamicId, new AresSubscriber<HttpResponse>() {
                @Override
                protected void onSuccess(HttpResponse response) {
                    mView.dynamicLike(like, position);
                }
            });
        } else {
            BizLayer.getInstance().getDynamicModule().dynamicUnLike(dynamicId, new AresSubscriber<HttpResponse>() {
                @Override
                protected void onSuccess(HttpResponse response) {
                    mView.dynamicLike(like, position);
                }
            });
        }
    }

    @Override
    public void followUser(String userId, boolean follow, int position) {
        FollowUserStatusRequest mFollowRequest = new FollowUserStatusRequest();
        List<String> list = new ArrayList<>();
        list.add(userId);
        mFollowRequest.setUidRels(list);
        mFollowRequest.setStatus(follow ? 1 : 0);

        BizLayer.getInstance().getAccountModule().postFollowOrUnfollowUser(mFollowRequest, new AresSubscriber<HttpResponse>() {
            @Override
            protected void onSuccess(HttpResponse response) {
                mView.followUser(position);
            }
        });
    }
}
